//
//  JMAuthModel.m
//  NewiOSProject
//
//  Created by apple on 2023/11/29.
//  Copyright © 2023 范智渊. All rights reserved.
//

#import "JMAuthCellModel.h"

@class JMAuthCellModel;
@implementation JMQuestionModel
-(BOOL)checkWithAuthCellModel:(JMAuthCellModel *)model andValue:(JMPickerSelectionModel *)value{
    [self save:model andValue:value];
    if (model.STEP==1) {
        BOOL isComplete = (self.overdue.length&&
                           self.overdueDays.length&&
                           self.totalOverdraft.length&&
                           self.loanNumber.length&&
                           self.outstanding
                           );
        
        return isComplete;
    }
    if (model.STEP==2) {
        BOOL isComplete = (self.idNo.length&&
                           self.realName.length&&
                           self.ossIdCardPositiveImg.length
                           );
        return isComplete;
    }
    if (model.STEP==3) {
        BOOL isComplete = (self.liveImg.length&&
                           self.livenessId.length
                           );
        return isComplete;
    }
    if (model.STEP==4) {
        BOOL isComplete = (self.birth.length&&
                           self.gender.length&&
                           self.delegationOrMunicipality.length&&
                           self.zh.length&&
                           self.email.length&&
                           self.maritalStatus&&
                           self.numberOfChildren&&
                           self.educationQualification
                           );
        return isComplete;
    }
    if (model.STEP==5) {
        BOOL isComplete = (self.jobStatus.length&&
                           self.industry.length&&
                           self.monthlyIncome.length&&
                           self.companyAddr&&
                           self.salaryType&&
                           self.salaryDay1
                           );
        return isComplete;
    }
    if (model.STEP==6) {
        BOOL isComplete = (self.relationship1.length&&
                           self.contact1Name.length&&
                           self.contact1.length&&
                           self.relationship2.length&&
                           self.contact2Name.length&&
                           self.contact2.length
                           );
        return isComplete;
    }
    if (model.STEP==7) {
        if ([model.title isEqualToString:@"CLABE o tarjeta bancaria"]) {
            self.isMatch = model.isMatch;
        }
        if ([model.title isEqualToString:@"Confirmar CLABE o tarjeta bancaria"]) {
            self.isEqual = model.isEqual;
        }
        BOOL isComplete = (self.bankCode.length&&
                           self.bankName.length&&
                           self.bankCard.length&&
                           self.bankCard1.length&&
                           self.isEqual&&self.isMatch
                           );
        return isComplete;
    }
    return NO;
}
-(void)save:(JMAuthCellModel *)model andValue:(JMPickerSelectionModel *)value{
    self.pageName = model.pageName;
    //1
    if ([model.actionType isEqualToString:@"Overdue_Focus"]) {
        self.overdue = value.value;
    }
    if ([model.actionType isEqualToString:@"Overdue_Days_Focus"]) {
        self.overdueDays = value.value;
    }
    if ([model.actionType isEqualToString:@"Loan_Total_Focus"]) {
        self.totalOverdraft = value.value;
    }
    if ([model.actionType isEqualToString:@"Loan_Count_Focus"]) {
        self.loanNumber = value.value;
    }
    if ([model.actionType isEqualToString:@"Loan_Repayment_Focus"]) {
        self.outstanding = value.value;
    }
    
    
    //2身份证
    if ([value isKindOfClass:NSDictionary.class]) {
        if (model.STEP==2) {
            NSDictionary *dict = value;
            self.idNo = dict[@"tongDunOCRResponseEntity"][@"idCardData"][@"idNumber"];
            self.realName = dict[@"tongDunOCRResponseEntity"][@"idCardData"][@"fullName"];
            self.ossIdCardPositiveImg = dict[@"photoName"];
        }
        if (model.STEP==3) {
            NSDictionary *dict = value;
            self.livenessId = dict[@"livenessId"];
            self.liveImg = dict[@"photoName"];
        }

    }
    if ([model.title isEqualToString:@"Nombre"]) {
        self.idNo = value.value;
    }
    if ([model.title isEqualToString:@"Numero"]) {
        self.realName = value.value;
    }
    //3实体
    
    //4个人信息
    if ([model.title isEqualToString:@"Fecha de Nacimiento"]) {
        self.birth = value.value;
    }
    if ([model.title isEqualToString:@"Sexo"]) {
        self.gender = value.value;
    }
    if ([model.title isEqualToString:@"Delegación o Municipio"]) {
        self.delegationOrMunicipality = value.value;
    }
    if ([model.title isEqualToString:@"Domicilio"]) {
        self.zh = value.value;
    }
    if ([model.title isEqualToString:@"Correo Electrónico"]) {
        self.email = value.value;
    }
    if ([model.title isEqualToString:@"Estado Civil"]) {
        self.maritalStatus = value.value;
        
    }
    if ([model.title isEqualToString:@"Número de Hijos"]) {
        self.numberOfChildren = value.value;
    }
    if ([model.title isEqualToString:@"Nivel de Educación"]) {
        self.educationQualification = value.value;
    }
    //5收入
    if ([model.title isEqualToString:@"Estado de Trabajo"]) {
        self.jobStatus = value.value;
    }
    if ([model.title isEqualToString:@"Sector"]) {
        self.industry = value.value;
    }
    if ([model.title isEqualToString:@"Salario mensual"]) {
        self.monthlyIncome = value.value;
    }
    if ([model.title isEqualToString:@"Nombre de la Empresa (Opcional)"]) {
        self.companyName = value.value;
    }
    if ([model.title isEqualToString:@"Teléfono de la Empresa (Opcional)"]) {
        self.companyPhone = value.value;
    }
    if ([model.title isEqualToString:@"Método de pago de salario"]) {
        self.salaryType = value.value;
    }
    if ([model.title isEqualToString:@"Día de pago de salario"]) {
        self.salaryDay1 = value.value;
    }
    if ([model.title isEqualToString:@"Día de pago de salario(Opcional)"]) {
        self.salaryDay2 = value.value;
    }
    if ([model.title isEqualToString:@"Dirección Completa de la Empresa"]) {
        self.companyAddr = value.value;
    }
    
   //6联系人
    if ([model.actionType isEqualToString:@"Contact_Relation1_Focus"]) {
        self.relationship1 = value.label;
    }
    if ([model.actionType isEqualToString:@"Contact1_Info_Focus"]) {
        self.contact1Name = value.value;
        if (value.label) {
            self.contact1 = value.label;
        }
    }
    if ([model.actionType isEqualToString:@"action_1"]) {
        self.contact1 = value.value;
    }
    if ([model.actionType isEqualToString:@"Contact_Relation2_Focus"]) {
        self.relationship2 = value.label;
    }
    if ([model.actionType isEqualToString:@"Contact2_Info_Focus"]) {
        self.contact2Name = value.value;
        if (value.label) {
            self.contact2 = value.label;
        }
    }
    if ([model.actionType isEqualToString:@"action_2"]) {
        self.contact2 = value.value;
    }
    
    //5
    
    if ([model.title isEqualToString:@"Nombre del banco"]) {
        self.bankCode = value.value;
        self.bankName = value.label;
    }
    if ([model.title isEqualToString:@"CLABE o tarjeta bancaria"]) {
        self.bankCard = value.value;
    }
    if ([model.title isEqualToString:@"Confirmar CLABE o tarjeta bancaria"]) {
        self.bankCard1 = value.value;
    }
   
}
-(NSDictionary *)toParam:(NSInteger)step{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    if (step==1) {
        NSDictionary *dict = @{
            // data 结构为
            @"data": @{
                @"overdue":self.overdue,
                @"overdueDays":self.overdueDays,
                @"totalOverdraft":self.totalOverdraft,
                @"loanNumber":self.loanNumber,
                @"outstanding":self.outstanding
          },
          @"step": @"CREDIT_INFO"
        };
        [param addEntriesFromDictionary:dict];
    }
    if (step==2) {
        NSDictionary *dict = @{
            @"data": @{
                @"idNo":self.idNo,
                @"realName":self.realName,
                @"ossIdCardPositiveImg":self.ossIdCardPositiveImg
          },
          @"step": @"IDENTITY_INFO"
        };
        [param addEntriesFromDictionary:dict];
    }
    if (step==3) {
        NSDictionary *dict = @{
            @"data": @{
                @"liveImg":self.liveImg,
                @"livenessId":self.livenessId,
          },
          @"step": @"LIVENESS_INFO"
        };
        [param addEntriesFromDictionary:dict];
    }
    if (step==4) {
        NSDictionary *dict = @{
            @"data": @{
                @"birth":self.birth,//用户的出生日期
                @"gender":self.gender,// 性别
                @"delegationOrMunicipality":self.delegationOrMunicipality,// 代表团
                @"zh":self.zh,// 居住城市
                @"email":self.email,// 邮箱
                @"maritalStatus":self.maritalStatus,// 婚姻状态
                @"numberOfChildren":self.numberOfChildren, // 子女数量
                @"educationQualification":self.educationQualification// 教育水平
          },
          @"step": @"PERSONAL_INFO"
        };
        [param addEntriesFromDictionary:dict];
    }
    if (step==5) {
        NSDictionary *dict = @{
            @"data": @{
                @"jobStatus":self.jobStatus,
                @"industry":self.industry,
                @"monthlyIncome":self.monthlyIncome,
                @"companyName":self.companyName,
                @"companyPhone":self.companyPhone,
                @"companyAddr":self.companyAddr,
                @"salaryType":self.salaryType,
                @"salaryDay1":self.salaryDay1,
                @"salaryDay2":self.salaryDay2
          },
          @"step": @"INCOME_INFO"
        };
        [param addEntriesFromDictionary:dict];
    }
    if (step==6) {
        NSDictionary *dict = @{
            @"data": @{
                @"contact1":self.contact1,
                @"contact1Name":self.contact1Name,
                @"relationship1":self.relationship1,
                @"contact2":self.contact2,
                @"contact2Name":self.contact2Name,
                @"relationship2":self.relationship2,
          },
          @"step": @"CONTACT_INFO"
        };
        [param addEntriesFromDictionary:dict];
    }
    if (step==7) {
        NSDictionary *dict = @{
            @"data": @{
            @"bankCode":self.bankCode,
            @"bankName":self.bankName,
            @"bankCard":self.bankCard
          },
          @"step": @"BANK_INFO"
        };
        [param addEntriesFromDictionary:dict];
    }
    return param;
}
@end



@implementation JMAuthCellModel

+(NSArray *)defalutModelArray{
    NSMutableArray *allQues =@[].mutableCopy;

    for (int i=0; i<7; i++) {
        if(i==0){//1
            NSArray *titles = @[
                @"Tiene deudas vencidas desde hace medio año?",//你的债务已经过期半年了吗？
                @"Cuál es el máximo de días de atraso en sus deudas vencidas?",//您到期债务的最长拖欠天数是多少？
                @"Cuánto es el total del préstamo actual que ha hecho por Internet?",//您目前在互联网上的贷款总额是多少
                @"Cuántas veces ha pedido un préstamo de dinero hasta el día de hoy？",//到目前为止，他已经申请了多少次贷款
                @"Cuántos préstamos se están pagando actu almente?"//目前正在偿还多少贷款？
            ];
            
            NSArray *placeHolders = @[@"Seleccione por favor",
                                      @"Seleccione por favor",
                                      @"Seleccione por favor",
                                      @"Seleccione por favor",
                                      @"Seleccione por favor"
            ];
            NSArray *actionTypes = @[@"Overdue_Focus",
                                     @"Overdue_Days_Focus",
                                     @"Loan_Total_Focus",
                                     @"Loan_Count_Focus",
                                     @"Loan_Repayment_Focus"
            ];
            NSArray *featureNames = @[@"Loan_Repayment",
                                     @"Overdue",
                                     @"Overdue_Total",
                                     @"Overdue_Days",
                                     @"Loan_Count"
            ];
            NSArray *shows = @[@"1",@"1",@"1",@"1",@"1"];
            NSMutableArray *ques1 = @[].mutableCopy;
            for (int i=0; i<titles.count; i++) {
                NSString *title =titles[i];
                JMAuthCellModel*model = JMAuthCellModel.new;
                model.vcTitle = @"Información básica";
                model.title = title;
                model.STEP = 1;
                model.pageName = @"VerifyQuestion";
                model.actionType = actionTypes[i];
                model.placeHolder = placeHolders[i];
                NSString *show = shows[i];
                model.showArrow =show.intValue;
                [ques1 addObject:model];
            }
            [allQues addObject:ques1];
        }
        
        if(i==1){//2
            NSArray *titles = @[@"Fachada",
                                @"Reversa",
                                @"Nombre",
                                @"Numero"];
            NSArray *placeHolders = @[@"Cara frontal del INE",
                                      @"Cara frontal del INE",
                                      @"Confirmar su nombre y apellido",
                                      @"Confirmar su número de identificación"
            ];
            NSArray *featureNames = @[@"ID_Front_Take",
                                     @"ID_Front_Take",
                                     @"Name_Input",
                                     @"IdNo_Input",
            ];
            NSArray *shows = @[@"0",@"0",@"0",@"0"];
            NSMutableArray *ques2 = @[].mutableCopy;
            for (int i=0; i<titles.count; i++) {
                NSString *title =titles[i];
                JMAuthCellModel*model = JMAuthCellModel.new;
                if (i==0) {
                    model.topTitle = @"Por favor escanea su identificación";
                }
                if (i==2) {
                    model.topTitle = @"Confirmar";
                }
                model.vcTitle = @"Documento de identidad";
                model.STEP = 2;
                model.title = title;
                model.pageName = @"VerifyKtp";
                model.placeHolder = placeHolders[i];
                NSString *show = shows[i];
                model.showArrow =show.intValue;
                [ques2 addObject:model];
            }
            [allQues addObject:ques2];

        }
        if (i==2) {
            NSMutableArray *ques3 = @[].mutableCopy;

            JMAuthCellModel*model = JMAuthCellModel.new;
            model.vcTitle = @"Foto vivo";
            model.STEP = 3;
            model.title = @"Foto vivo";
            model.pageName = @"VerifyFacial";
            model.placeHolder = @"*Las fotos que suba deben coincidir con las fotos de \nsu identificación";
            model.featureName = @"Liveness_Click";
            [ques3 addObject:model];
            [allQues addObject:ques3];
        }
        if (i==3) {
            NSArray *titles = @[
                @"Fecha de Nacimiento",//出生日期
                @"Sexo",//性别
                @"Delegación o Municipio",//代表团或市政当局
                @"Domicilio",//住所
                @"Correo Electrónico",//电子邮件
                @"Estado Civil",//婚姻状况
                @"Número de Hijos",//子女数量
                @"Nivel de Educación"//教育水平
            ];
            
            NSArray *placeHolders = @[@"Seleccione por favor",
                                      @"Seleccione por favor",
                                      @"Por favor escribe",
                                      @"Seleccione por favor",
                                      @"Por ejemplo xxxxxx@gmail.com",
                                      @"Seleccione por favor",
                                      @"Seleccione por favor",
                                      @"Seleccione por favor"
                                      
            ];
            NSArray *actionTypes = @[@"Birthday_Focus",
                                     @"Gender_Focus",
                                     @"Delegation_Focus",
                                     @"Address_Focus",
                                     @"EMail_Focus",
                                     @"Civil_Status_Focus",
                                     @"Children_Count_Focus",
                                     @"Education_Level_Focus"
            ];
            NSArray *typeStrings = @[@"",
                                     @"GENDER",
                                     @"",
                                     @"ZH",
                                     @"",
                                     @"MARITAL_STATUS",
                                     @"CHILDREN_NUMBER",
                                     @"EDUCATION_QUALIFICATION",
            ];
            NSArray *featureNames = @[@"Birthday",
                                      @"Gender",
                                      @"Delegation",
                                      @"Address",
                                      @"EMail_Input",
                                      @"Civil_Status",
                                      @"Children_Count",
                                      @"Education_Level",
            ];
            NSArray *shows = @[@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"1"];
            NSMutableArray *ques4 = @[].mutableCopy;
            for (int i=0; i<titles.count; i++) {
                NSString *title =titles[i];
                JMAuthCellModel*model = JMAuthCellModel.new;
                model.vcTitle = @"Información básica";
                model.title = title;
                model.STEP = 4;
                model.pageName = @"VerifyPerson";
                model.actionType = actionTypes[i];
                model.placeHolder = placeHolders[i];
                model.typeString = typeStrings[i];
                NSString *show = shows[i];
                model.showArrow =show.intValue;
                [ques4 addObject:model];
                if (i==titles.count-1) {
                    model.errorMessage = @"*Cargue los siguientes datos para mejorar su evaluación crediticia ";
                }
            }
            [allQues addObject:ques4];
        }
        if (i==4) {
            NSArray *titles = @[
                @"Estado de Trabajo",//工作状态
                @"Sector",//部门
                @"Salario mensual",//月薪
                @"Nombre de la Empresa (Opcional)",//公司名称
                @"Teléfono de la Empresa (Opcional)",//公司电话
                @"Método de pago de salario",//工资支付方式
                @"Día de pago de salario",//工资支付日
                @"Día de pago de salario(Opcional)",//工资支付日2
                @"Dirección Completa de la Empresa"//完整的公司地址
            ];
            
            NSArray *placeHolders = @[@"Seleccione por favor",
                                      @"Seleccione por favor",
                                      @"Seleccione por favor",
                                      @"Por favor escribe",
                                      @"Por favor escribe",
                                      @"Seleccione por favor",
                                      @"Fecha del primer salario del mes",
                                      @"Fecha del segundo salario del mes",
                                      @"Por favor escribe"
                                      
            ];
            NSArray *actionTypes = @[@"Work_Status_Focus",
                                     @"Sector_Focus",
                                     @"Monthly_Income_Focus",
                                     @"Company_Name_Focus",
                                     @"Company_Phone_Focus",
                                     @"Salary_Method_Focus",
                                     @"Salary_Day1_Focus",
                                     @"Salary_Day2_Focus",
                                     @"Company_Address_Focus"
            ];
            NSArray *typeStrings = @[@"JOB_TYPE",
                                     @"INDUSTRY",
                                     @"MONTHLY_INCOME",
                                     @"",
                                     @"",
                                     @"SALARY_TYPE",
                                     @"",
                                     @"",
                                     @"",
            ];
            NSArray *featureNames = @[@"Work_Status",
                                      @"Sector",
                                      @"Monthly_Income",
                                      @"Company_Name_Input",
                                      @"Company_Phone_Input",
                                      @"Salary_Method",
                                      @"Salary_Day1",
                                      @"Salary_Day2",
                                      @"Company_Address_Input"
            ];
            NSArray *shows = @[@"1",@"1",@"1",@"0",@"0",@"1",@"1",@"1",@"0"];
            NSMutableArray *ques4 = @[].mutableCopy;
            for (int i=0; i<titles.count; i++) {
                NSString *title =titles[i];
                JMAuthCellModel*model = JMAuthCellModel.new;
                model.vcTitle = @"Información básica";
                model.title = title;
                model.STEP = 5;
                model.pageName = @"VerifyIncome";
                model.actionType = actionTypes[i];
                model.placeHolder = placeHolders[i];
                model.typeString = typeStrings[i];
                NSString *show = shows[i];
                model.showArrow =show.intValue;
                [ques4 addObject:model];
               
                if (i==titles.count-1) {
                    model.errorMessage = @"*Cargue los siguientes datos para mejorar su evaluación crediticia ";
                }
            }
            [allQues addObject:ques4];
        }
        if(i==5){//3
            NSMutableArray *arr = @[].mutableCopy;
            
            //第一联系人
            NSArray *leftTitles = @[@"Parentesco",@"Nombre",@"Número de teléfono"];;
            NSArray *shows1 = @[@"1",@"1",@"0"];
            NSMutableArray *ques3 = @[].mutableCopy;
            NSArray *actionTypes1 = @[@"Contact_Relation1_Focus",
                                      @"Contact1_Info_Focus",
                                      @"action_1",
            ];
            NSArray *placeHolders = @[@"Seleccione por favor",
                                      @"Por favor, introduzca",
                                      @"Por favor, introduzca",
                                      
            ];
            NSArray *featureNames = @[@"Contact_Relation1",
                                      @"Contact_Name_Input1",
                                      @"Contact_Phone_Input1",
                                      
            ];
            for (int i=0; i<leftTitles.count; i++) {
                JMAuthCellModel*model = JMAuthCellModel.new;
                model.vcTitle = @"Información de contactos";
                model.title = leftTitles[i];
                model.pageName = @"VerifyContact";
                model.STEP = 6;
                model.leftImgName = [NSString stringWithFormat:@"auth_left_%@",leftTitles[i]];
                if (i==1) {
                    model.rightImgName =[NSString stringWithFormat:@"auth_right_%@",leftTitles[i]];
                }
                model.placeHolder = placeHolders[i];

                NSString *show = shows1[i];
                model.showArrow =show.intValue;
                model.actionType = actionTypes1[i];
                if (i==0) {
                    model.topTitle = @"Primer contacto";
                    model.typeString = @"RELATIONSHIP1";
                }
                [ques3 addObject:model];
            }
            
            //第二联系人
            NSArray *leftTitles2 = @[@"Parentesco",@"Nombre",@"Número de teléfono"];;
            NSArray *shows2 = @[@"1",@"1",@"0"];
            NSArray *actionTypes2 = @[@"Contact_Relation2_Focus",
                                      @"Contact2_Info_Focus",
                                      @"action_2",
            ];
            NSArray *featureNames2 = @[@"Contact_Relation2",
                                      @"Contact_Name_Input2",
                                      @"Contact_Phone_Input2",
                                      
            ];
            for (int i=0; i<leftTitles2.count; i++) {
                JMAuthCellModel*model = JMAuthCellModel.new;
                model.vcTitle = @"Información de contactos";
                model.title = leftTitles2[i];
                model.pageName = @"VerifyContact";
                model.STEP = 6;
                model.leftImgName = [NSString stringWithFormat:@"auth_left_%@",leftTitles2[i]];
                if (i==1) {
                    model.rightImgName =[NSString stringWithFormat:@"auth_right_%@",leftTitles2[i]];
                }
                model.placeHolder = placeHolders[i];

                NSString *show = shows2[i];
                model.showArrow =show.intValue;
                model.actionType = actionTypes2[i];
                if (i==0) {
                    model.topTitle = @"Segundo contacto";
                    model.typeString = @"RELATIONSHIP2";
                }
                [ques3 addObject:model];
            }
            [allQues addObject:ques3];
        }
       
        
        if(i==6){//5
            NSArray *titles = @[@"Nombre del banco",@"CLABE o tarjeta bancaria",@"Confirmar CLABE o tarjeta bancaria"];
            NSArray *placeHolders = @[@"Seleccione por favor",
                                      @"Por favor escribe",
                                      @"Por favor escribe"];
            NSArray *shows = @[@"1",@"0",@"0"];
            NSArray *actionTypes1 = @[@"Bank_Name_Focus",
                                      @"CLABE1_Focus",
                                      @"CLABE2_Focus",
            ];
            NSArray *featureNames = @[@"Bank_Name",
                                      @"Bank_Card_Input1",
                                      @"Bank_Card_Input2",
                                      
            ];
            NSMutableArray *ques5 = @[].mutableCopy;
            for (int i=0; i<titles.count; i++) {
                NSString *title =titles[i];
                JMAuthCellModel*model = JMAuthCellModel.new;
                model.vcTitle = @"Información de contactos";
                model.title = title;
                model.pageName = @"VerifyBankcard";
                model.placeHolder = placeHolders[i];
                model.STEP = 7;
                model.actionType = actionTypes1[i];
                if (i==0) {
                    model.type = 6;
                }
                if (i==1) {
                    model.errorMessage =  @"*Por favor poner su núemro CLABE INTERBANCARIA como aparece en su Estado de Cuenta, asegurarse que sea de 18 dígitos. O poner su número de tarjeta bancaria como aparece en su tarjeta, asegurarse que sea de 16 dígitos.";
                }
                if (i==2) {
                    model.errorMessage = @"*El número de la cuenta bancaria no coincide";
                }
                
                NSString *show = shows[i];
                model.showArrow =show.intValue;
                [ques5 addObject:model];
            }
            [allQues addObject:ques5];
        }
    }
    return allQues;
}
@end
